-- Decompiled with the Synapse X Luau decompiler.

local l__ServerOHOH__1 = _G.ServerOHOH;
local M = l__ServerOHOH__1.class.new(script);

local function number2string(p1)
	if type(p1) ~= "table" then
		return p1;
	end;
	local v3 = {};
	for v4, v5 in pairs(p1) do
		if type(v4) == "number" then
			v4 = tostring(v4);
		end;
		v3[v4] = number2string(v5);
	end;
	return v3;
end;
local function string2number(p2)
	if type(p2) ~= "table" then
		return p2;
	end;
	local v6 = {};
	for v7, v8 in pairs(p2) do
		v6[tonumber(v7) or v7] = string2number(v8);
	end;
	return v6;
end;


local RemoteFunction =Instance.new("RemoteFunction",game.ReplicatedStorage)
-- local RemoteFunction = l__ServerOHOH__1:GetPath_Loop("ReplicatedStorage.RemoteFunction");
local FuncData = {};
local Player_Fuc_Data = {};

local InstanceManager = l__ServerOHOH__1.load.InstanceManager();

local function RunFuc(playerObj, fucId, ...)
	local fuc = FuncData[fucId];
	if not fuc then
		return;
	end;
	if Player_Fuc_Data[playerObj] and Player_Fuc_Data[playerObj][fucId] then
		return false, "function is active";
	end;
	Player_Fuc_Data[playerObj] = Player_Fuc_Data[playerObj] or {};
	Player_Fuc_Data[playerObj][fucId] = os.clock();
	
	local runData = { fuc(playerObj, ...) };

	Player_Fuc_Data[playerObj][fucId] = nil;
	
	if not next(Player_Fuc_Data[playerObj]) then
		Player_Fuc_Data[playerObj] = nil;
	end;
	
	for v13, v14 in ipairs(runData) do
		runData[v13] = number2string(v14);
	end;
	
	return table.unpack(runData);
end;

local Delay_Fuc_Data = {}; --缓存远程调用函数

function RemoteFunction.OnServerInvoke(player, fucId, ...)
		
	local playerObj = InstanceManager:FindObject(player);
	local argData = {};
	for k, v in ipairs({ ... }) do
		argData[k] = string2number(v);
	end;
	if playerObj then
		return RunFuc(playerObj, fucId, table.unpack(argData));
	end;
	
	--服务器还不存在对象，缓存起来
	Delay_Fuc_Data[player] = Delay_Fuc_Data[player] or {};
	table.insert(Delay_Fuc_Data[player], {
		name = fucId, 
		args = { ... }, 
		co = coroutine.running()
	});
	return coroutine.yield();
end;
function M.SetHandle(self, fucId, func)
	FuncData[fucId] = func;
end;
local u14 = {};
function M.Invoke(p10, p11, p12, ...)
	if u14[p11] and u14[p11][p12] then
		return;
	end;
	Player_Fuc_Data[p11] = Player_Fuc_Data[p11] or {};
	u14[p11][p12] = os.time();
	local v19 = {};
	for v20, v21 in ipairs({ ... }) do
		v19[v20] = number2string(v21);
	end;
	RemoteFunction:InvokeClient(p11.main_inst, p12, table.unpack(v19));
	u14[p11][p12] = nil;
	if not next(u14[p11]) then
		u14[p11] = nil;
	end;
	return table.unpack((string2number(nil)));
end;

--执行为创建前的远程函数调用
function M.DelayGet(p13, p14)
	local v22 = Delay_Fuc_Data[p14.main_inst];
	if v22 then
		for v23, v24 in ipairs(v22) do
			coroutine.yield("OHOH_wait");
			coroutine.resume(v24.co, RunFuc(p14, v24.name, table.unpack(v24.args)));
		end;
	end;
end;
return M;
